import static java.lang.Thread.sleep;
class Counter{
    public int sum=0;
    public Counter(){

    }
    public Counter(int n){
        this.sum=n;
    }
    public synchronized void increase(){
        sum++;
    }
}
public class demo1 {

    static int count=0;


    public static void main(String[] args) throws InterruptedException {
        Counter counter=new Counter();
        Thread t1=new Thread(()->{
             for(int i=0;i<5000;i++){
               counter.increase();
             }
        });
        Thread t2=new Thread(()->{
            for(int i=0;i<5000;i++){
                counter.increase();
            }
        });
        Thread.sleep(1000);
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(counter.sum);
    }


    public static void main1(String[] args) throws InterruptedException {

        Thread thread1=new Thread(()->{
            for(int i=0;i<5000;i++){
                count++;
            }
        });
        Thread thread2=new Thread(()->{
            for(int i=0;i<5000;i++){
                count++;
            }
        });
        thread1.start();
       //thread1.join();
        thread2.start();
        thread2.join();
        sleep(1000);
        System.out.println(count);
    }
}